package main

import (
	"fmt"
	"gopkg.in/yaml.v2"
	"os"
)

type TLS struct {
	Enable    bool   `yaml:"enable"`
	Cacrt     string `yaml:"cacrt"`
	Clientcrt string `yaml:"clientcrt"`
	Clientkey string `yaml:"clientkey"`
}

type DeviceSub struct {
	Yx       string `yaml:"yx"`
	Yk       string `yaml:"yk"`
	Yc       string `yaml:"yc"`
	Yt       string `yaml:"yt"`
	Setreply string `yaml:"setreply"`
	Property string `yaml:"property"`
}
type Subscriber struct {
	Device  DeviceSub `yaml:"device"`
	Gateway DeviceSub `yaml:"gateway"`
}
type DevicePub struct {
	Yx          string `yaml:"yx"`
	Yk          string `yaml:"yk"`
	Yc          string `yaml:"yc"`
	Yt          string `yaml:"yt"`
	Property    string `yaml:"property"`
	Ykset       string `yaml:"ykset"`
	Ytset       string `yaml:"ytset"`
	Propertyset string `yaml:"propertyset"`
}
type Publish struct {
	Device  DevicePub `yaml:"device"`
	Gateway DevicePub `yaml:"gateway"`
}
type Mqtt struct {
	Serverip   string     `yaml:"serverip"`
	Port       int        `yaml:"port"`
	User       int        `yaml:"user"`
	Passwd     int        `yaml:"passwd"`
	ClientID   string     `yaml:"clientId"`
	TLS        TLS        `yaml:"tls"`
	Subscriber Subscriber `yaml:"subscriber"`
	Publish    Publish    `yaml:"publish"`
}
type MqttConfig struct {
	Mqttcfg Mqtt `yaml:"mqtt"`
}

func CfgInit() {
	config := MqttConfig{}
	file, err := os.ReadFile("./config/mqttcfg.yaml")
	if err != nil {
		fmt.Println("Error reading config.yaml")
		return
	}
	err = yaml.Unmarshal(file, &config)
	if err != nil {
		fmt.Println("Error parsing config.yaml")
	}
}
